<template>
	<el-drawer title="快捷菜单设置" v-model="visible" :size="600" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-main>
				<el-transfer
					filterable
					:filter-method="filterMethod"
					filter-placeholder="请输入菜单名称"
					:titles="['备选菜单', '已选菜单']"
					v-model="form.menuId"
					target-order="push"
					:data="menuList">
				</el-transfer>
				<el-footer style="text-align: center;">
					<el-button @click="visible=false">关闭</el-button>
					<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
				</el-footer>
			</el-main>
		</el-container>
	</el-drawer>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	components: {},
	data() {
		return {
			loading: false,
			menuList: [],
			form: {
				menuId: []
			},
			visible: false,
			isSaveing: false,
			filterMethod(query, item) {
				return item.label.indexOf(query) > -1;
			},
		}
	},
	mounted() {
		this.getSysMenuInRoleForShortMenu();
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this;
		},
		async submit() {
			this.isSaveing = true;
			let menuIdStr=this.form.menuId.join(",")
			var res = await this.$API.system.shortMenu.setMyShortMenu.post({menuIdStr:menuIdStr});
			if (res.code == 200) {
				this.$emit('success')
				this.visible = false;
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
				this.isSaveing = false;
			}
		},
		async getSysMenuInRoleForShortMenu() {
			var res = await this.$API.system.shortMenu.getSysMenuInRoleForShortMenu.get();
			if (res.code == 200) {
				for (let i = 0; i < res.data.length; i++) {
					this.menuList.push({key: res.data[i].id, label: res.data[i].meta.title});
				}
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//表单注入数据
		setData(data) {
			data.forEach(item => {
				this.form.menuId.push(item.id);
			});
		},
	}
}
</script>

<style>
</style>
